package com.dy.seleniumlearn;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;
//通过xml文件运行该类
public class WebElementOp3 {
    WebDriver driver;
    WebDriver.Navigation navigation;

    @BeforeMethod
    @Parameters("Browser")
    public void SetUp(String Browser) {
        if(Browser.equalsIgnoreCase("firefox")){
            System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
            driver = new FirefoxDriver();
        }else {
            System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
            driver = new org.openqa.selenium.chrome.ChromeDriver();

        }
        navigation = driver.navigate();
    }

    @Test
    public void test() {
        driver.get("http://39.101.198.110/testhtml/exam/House.html");
//        System.out.println(driver.getTitle());
//        Assert.assertEquals(driver.getTitle(), "房源信息");
//        System.out.println(driver.findElement(By.cssSelector("[target='']")).getText());
//         获取请求的urlurl
//        System.out.println(driver.getCurrentUrl());
//         断言某个页面是否包含某信息，通常用来判断某个功能是否执行成功
//        System.out.println(driver.getPageSource());
//        Assert.assertTrue(driver.getPageSource().contains("房源信息"));
        List<WebElement> list=new ArrayList<>();
        list.add(driver.findElement(By.name("c1")));
        list.add(driver.findElement(By.name("c2")));
        for (WebElement webElement : list) {
            if (!webElement.isSelected()){
                webElement.click();
            }
            System.out.println(driver.findElement(By.name("c1")).getTagName());
            System.out.println(driver.findElement(By.className("edit")).getTagName());
            System.out.println(driver.findElement(By.name("username")).isEnabled());
            System.out.println(driver.findElement(By.className("edit")).isDisplayed());
            System.out.println(driver.findElement(By.name("username")).getAttribute("value"));
        }

    }

    @AfterMethod
    public void afterMethod() {
        //driver.close();
    }
}
